import nodeFileSys from "fs";
export type TEncoding = "" | "utf8" | "binary";
export function readDir(dirname: string, options?: { encoding: string } & { withFileTypes: true }): Promise<string[]>
{
    return new Promise((resolve, reject) => {
        nodeFileSys.readdir(dirname, options as any, (err, files) => {
            if (err) {
                reject(err);
            } else {
                resolve(files);
            }
        });
    });
}

export function readFile(filename: string, encoding?: TEncoding): Promise<string | Buffer> {
    return new Promise((resolve, reject) => {
        nodeFileSys.readFile(filename, encoding as any, (err, data) => {
            if (err) {
                reject(err);
            } else {
                resolve(data);
            }
        });
    });
}

export function getStatOf(filename: string):Promise<nodeFileSys.Stats> {
    return new Promise((resolve, reject) => {
       nodeFileSys.lstat(filename, (err, state) => {
           if (err) {
               reject(err);
           } else {
               resolve(state);
           }
       }) ;
    });
}

export {
    nodeFileSys
};
